<?php

namespace app\index\controller;
use think\Session;

use Think\Controller;
use think\Request;
header('Access-Control-Allow-Origin:*');
class Index  extends \think\Controller {

	public function index() {
		
		$username = Session::get('username');
		$session_id = Session::get('session_id');
		//判断session_id是否异地登录（单点登录）
		$rs = \think\Db::table('bk_admin') -> where('username', $username) -> find();
		$user_id = $rs['session_id'];
		if($user_id!= $session_id){
			session(null);
		};
		
		
		if (!Session::has('username')) {
			return redirect('index/login/login');
		};
		
		$this -> assign('username', $username);
		
		
		return $this -> fetch();

	}

	public function user() {
		if (Request::instance() -> isGet()) {
			if (Session::has('username')) {
				$username = Session::get('username');
				$mines = array('username'=>$username,'id'=>1000,'status'=>'online','sign'=>'xxx','avatar'=>'');
				$mine = array('mine'=>$mines);
				return json(['code'=>0,'msg'=>'','data'=>$mine]);
			}
		}

	}

	public function index_exit() {
		if (Request::instance() -> isGet()) {
			session(null);
		}

	}

}
